//
// Created by 23602 on 25-8-23.
//

#ifndef SCENCE_HPP
#define SCENCE_HPP
#include <cmath>
#include <math.h>
#include <SFML/Graphics.hpp>
#include <tuple>
#include "light.hpp"
#include "sphere.hpp"

#include <iostream>

using namespace sf;
using std::cout, std::endl;
Vector3f reflectRay(const Vector3f& L, const Vector3f& N);

class Scene
{
public:


    double computeLighting(const Vector3f& p, const Vector3f& N, const Vector3f& V, const Sphere& sphere);
    std::tuple<Sphere*, double> closestIntersect(const Vector3f& origin, const Vector3f& direction, double minT, double maxT = INFINITY);

    std::tuple<double, double> intersectRaySpere(const Vector3f& origin, const Vector3f& direction, Sphere& sphere);

    Color traceRay(const Vector3f& origin, const Vector3f& direction, float minT, float maxT = INFINITY, uint8_t recursiveCnt = 1);

private:
    const sf::Color bgColor = sf::Color::Black;
    float viewportSizeX = 1.0;
    float viewportSizeY = 1.0;
    float projectionPlanD = 1.0;

    Sphere sphere1 = Sphere({0, -1, 3}, 1, {255, 0, 0}, 500, 0.2);
    Sphere sphere2 = Sphere({2, 0, 4}, 1, {0, 0, 255}, 500, 0.3);
    Sphere sphere3 = Sphere({-2, 0, 4}, 1, {0, 255, 0}, 10, 0.4);
    Sphere sphere4 = Sphere({{0, -5001, 0}, 5000, {255, 255, 0}, 500, 0.1}); // 异常闪亮

    std::vector<Sphere> spheres = {
        sphere1, sphere2, sphere3, sphere4
    };
    std::vector<Vector3f> vertices;

    std::vector<Light> lights = {
        {LightType::Ambient, 0.2},
        {LightType::Point, 0.6, {2, 1, 0}},
        {LightType::Directional, 0.2, {1, 4, 4}},
    };
};


#endif //SCENCE_HPP
